<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<#include "../inc/commonJs.html">
<title>Insert title here</title>
<script type="text/javascript">
	// 工具栏
	var toolbar = [ {
		id : 'button-add',
		text : '增加',
		iconCls : 'icon-add',
		handler : doAdd
	},'-', {
		id : 'button-view',	
		text : '修改',
		iconCls : 'icon-edit',
		handler : doView
	},'-', {
		id : 'button-delete',
		text : '删除',
		iconCls : 'icon-cancel',
		handler : doDelete
	}];
	//定义冻结列
	var frozenColumns = [ [ {
		field : 'useid',
		checkbox : true,
		rowspan : 2
	}] ];
	// 定义标题栏
	var columns = [ [ {
		field : 'username',
		title : '用户名称',
		width : 200,
		rowspan : 2,
		align : 'center'
	},{
		field : 'goodsname',
		title : '物品名称',
		width : 100,
		rowspan : 2,
		align : 'center'
	},{
		field : 'num',
		title : '数量',
		width : 200,
		rowspan : 2,
		align : 'center'
	},{
		field : 'dt',
		title : '时间',
		width : 150,
		rowspan : 2,
		align : 'center'
	},{
		field : 'zt',
		title : '状态',
		width : 100,
		rowspan : 2,
		align : 'center',
		formatter: function(value,row,index){
			if (value==0){
				return '申请中';
			} else {
				return '已通过';
			}
		}
	} ]];
	$(function(){
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			striped : true,
			singleSelect:true,
			loadMsg : '数据装载中......',
			pageSize:[30],
			pageList: [30,50,100],
			pagination : true,
			toolbar : toolbar,
			url : "selectGoodsUseApplyList.do",
			idField : 'useid',
			frozenColumns : frozenColumns,
			columns : columns,
			onClickRow : onClickRow,
			onDblClickRow : doDblClickRow
		});
		
		$('#goodsWindow').dialog({
	        title: '查看物品',
	        width: 400,
	        modal: true,
	        shadow: true,
	        closed: true,
	        onClose:function(){
	        	$('#goodsid').val('');
	        	$('#name').val('');
	        	$('#zt').val('');
	        },
	        buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					$('#goodsForm').form('submit', {
					    url:'saveGoodsUse.do',
					    onSubmit: function(param){
					    	var isValid = $(this).form('validate');
							return isValid;
					    },
					    success:function(data){
					    	$("#goodsWindow").dialog('close');
					    	$('#grid').datagrid('reload');
					    	$('#grid').datagrid('uncheckAll');
					    	$.messager.show({
								title:'信息提示',
								msg:data
							});
					    }    
					}); 
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$("#goodsWindow").dialog('close');
				}
			}]
	    });
		
		$('#goodsid').combobox({ 
		    url:'selectGoods.do',
		    valueField:'goodsid',    
		    textField:'name'
		});
		
	});
	// 双击
	function doDblClickRow(rowIndex, rowData) {
		
	};
	// 单击
	function onClickRow(rowIndex){
		
	}
	
	function doAdd() {
		$("#goodsWindow").dialog('open').dialog('center');
	}

	function doView() {
		var item = $('#grid').datagrid('getSelected');
		if(item!=null){
			$('#goodsForm').form('load','selectOneGoodsUse.do?useid='+item.useid);
			$("#goodsWindow").dialog('open').dialog('center'); 
		}else{
			$.messager.alert("信息提示","查看物品必须选中一行信息","error");
		}
	}

	function doDelete() {
		var ids = [];
		var items = $('#grid').datagrid('getSelections');
		if(items.length == 0){
			$.messager.alert("信息提示","删除物品必须选中一行信息","error");
			return ;
		}
		$.messager.confirm("操作提示", "删除物品！",function(r){
			if(r){
				for(var i=0; i<items.length; i++){
				    ids.push(items[i].useid);	    
				}
				 $.post("delGoodsUse.do", {useid :ids.join(",") }, function(data){
							$.messager.show({
								title:'信息提示',
								msg:data
							});
							$("#grid").datagrid('reload');
							$('#grid').datagrid('uncheckAll'); // 取消所有元素选中效果
				});  
			}
		});
	}
	
</script>	
</head>
<body>
<div class="easyui-panel" data-options="fit:true,border:false">
   	<table id="grid" data-options="fit:true,border:false"></table>
	<div  id="goodsWindow">
		<form id="goodsForm" method="post">
			 <table class="table-edit" width="80%" align="center" border="1" cellspacing="0" cellpadding="0" style=" margin-top:10px; border-collapse: collapse; border:#ccc 1px solid;">
			 	<tr >
	    			<td height="35" align="right"><span class="smallFont">申请物品:</span></td>
	    			<td align="center">
	    				<input id="goodsid" name="goodsid" style="width:200px;" />   
	    			</td>
    			</tr>
			 	<tr >
	    			<td height="35" align="right"><span class="smallFont">数量:</span></td>
	    			<td align="center">
	    				<input class="easyui-numberbox" data-options="required:true" type="text" id="num" name="num" style="width:200px;" />
	    			</td>
    			</tr>
			 </table>
		</form>
	</div>
</div>
</body>
</html>